package com.wdd.recoveryvehicle.loginUser.service.impl;

import com.wdd.recoveryvehicle.loginUser.bean.LoginCompanyVB;
import com.wdd.recoveryvehicle.loginUser.bean.LoginPermissionVB;
import com.wdd.recoveryvehicle.loginUser.bean.LoginRolesVB;
import com.wdd.recoveryvehicle.loginUser.bean.LoginUserVB;
import com.wdd.recoveryvehicle.loginUser.service.LoginUserService;
import com.wdd.recoveryvehicle.loginUser.service.TokenService;
import com.wdd.recoveryvehicle.mapper.LoginUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

@Service
public class LoginUserServiceImpl implements LoginUserService {

    @Autowired
    private LoginUserMapper loginUserMapper;

    public LoginUserVB selectLoginUserVBByUserNickname(String user_nickname) {
        LoginUserVB loginUserVB = loginUserMapper.selectLoginUserVBByUserNickname(user_nickname);
        if (loginUserVB != null) {
            Set<LoginRolesVB> loginRolesVBS = loginUserMapper.selectLoginRoleVBByUserId(loginUserVB.getUser_id());
            if (loginRolesVBS != null) {
                for (LoginRolesVB rolesVB : loginRolesVBS) {
                    Set<LoginPermissionVB> permissionVBS = loginUserMapper.selelectLoginPermissionVBByRoleId(rolesVB.getRole_id());
                    rolesVB.setLoginPermissionVBS(permissionVBS);
                }
            }
            loginUserVB.setLoginRolesVBS(loginRolesVBS);
            LoginCompanyVB loginCompanyVB = loginUserMapper.selectLoginCompanyVBByUserId(loginUserVB.getUser_id());
            loginUserVB.setLoginCompanyVB(loginCompanyVB);
        }
        return loginUserVB;
    }

    @Override
    public LoginUserVB selectLoginUserVBByUserId(String user_id) {
        return loginUserMapper.selectLoginUserVBByUserId(user_id);
    }

}
